<style>.top_font_tail{color:rgb(30 122 195);line-height: 18px;font-size: 14px;font-weight: 700;font-family: SourceHanSansSC;}
.top_font_tail .tuichuok:hover{color:#FFFFFF}
#total_Num{}.tuichuok{background:rgb(30 122 195);color:#FFFFFF}
.fixed-bar-tr-header{top: -2px!important;padding:1px!important;}
.pb50{padding-left: 10px;padding-right: 10px;padding-bottom: 20px!important;}
.layui-table, .layui-table-view{padding:0px!important;margin-top: -8px;}

/*库存录入样式*/
.dress_line_code{margin-top:6px;}
.dress_line_code textarea{height:100px;padding:6px;width:578px}
.submit_block{padding-left:230px;}
.checkin_ret{text-align:center;padding-top:30px;}
.scan_code_ret{color:red;font-weight:bold;margin-bottom:6px;}
.defective_reason input{padding:2px 4px;}

</style>
<script type="text/html" id="OrdernumTpl">
	<span class="copy-item">{{ d.client_ordernum }}</span> <br>
</script>
<script type="text/html" id="SKUTpl">
	<span class="copy-item">{{ d.sku }}</span> <br>
</script>

<div id="StockCheckOut" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
		<div class="layui-form-item pt20 pl20">
			<div class="scan_code">
				<div class="dress_line_code">
					请扫描要出库的服装：(注：一行一个服装条码)<br />
					<textarea name="out_dress_line_code" id="out_dress_line_code" class="layui-area out_code_input" lay-verify="" placeholder="扫描要出库的服装条码"></textarea>
					<input type="hidden" name="sku_stock" class="sku_stock" value='{{d.sku_stock}}'>
				</div>
				<div class="scan_code_block">验证提示：<span class="scan_code_ret"></span></div>
				<div class="submit_block">
					<button class="layui-btn" lay-submit lay-filter="stock-out-out" >确认出库</button>
				</div>
			</div>
			<div class="checkin_ret hide">处理结果：<span class="act_ret_str"></span>出库成功；<br /></div>
			<div>
				&nbsp;
			</div>
			<input type="hidden" name="order_id" value="{{ d.order_id }}">
			<input type="hidden" name="url" value="{{ d.url }}">
			<input type="hidden" name="size_name" class="size_name_input" value="" lay-reqText="尺码请选择">
			<input type="hidden" name="number" value="" lay-verify="required" lay-reqText="请扫描要出库的服装条码"  class="layui-input outcheckinNum">
			<div>&nbsp;</div>
		</div>
	</form>
</div>

<div id="stockOutInTpl" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
		<div class="layui-form-item pt20 pl20">
			{{#  for(var i in d.list){ }}
			<div class="layui-inline">
				<label class="layui-form-label">{{ d.list[i].size_name }}</label>
				<div class="layui-input-inline">
					<input type="text" name="number[{{ d.list[i].mid }}]" value="" lay-verify="number|required" placeholder="输入数量" class="layui-input">
				</div>
			</div>
			{{#  } }}

			<input type="hidden" name="order_id" value="{{ d.order_id }}">
			<input type="hidden" name="url" value="{{ d.url }}">
			<div class="layui-inline fr">
				<button class="layui-btn" lay-submit lay-filter="stock-out-in" >确认</button>
			</div>
		</div>
	</form>
</div>

<div id="StockCheckIn" class="hide">
	<form class="layui-form layui-form-pane" lay-verify="" action="" method="get">
		<div class="layui-form-item pt20 pl20">
			<div align="center">
				<label class="layui-btn layui-btn-danger show_code_input" size_name="{{ d.size_name }}">{{ d.size_name }}</label>
			</div>
			<div class="scan_code">
				<div class="dress_line_code">
					当前录入的尺码：<span class="size_name_span">{{ d.size_name }}</span>，数量：<span class="checkInNumSpan">0</span>件 (注意：一个条码为一件)<br />
					<textarea name="dress_line_code" id="dress_line_code" class="layui-area code_input" lay-verify="" placeholder="扫服装条码"></textarea>
				</div>
			<!--	<div class="defective_reason hide">次品原因：<input type="text" name="defective_reason" value="" placeholder="输入次品原因(非必填)">
					<input type="hidden" name="stocktype" class="stocktype_input" value="">
				</div>-->
				<div class="submit_block">
					<button class="layui-btn" lay-submit lay-filter="stock-out-in" >确认入库</button>
				</div>
			</div>
			<div class="checkin_ret hide">处理结果：尺码：<span class="size_name_span"></span>，数量：<span class="checkInNumSpan">0</span>件，入库成功；<br />
				当前订单该尺码总库存：<span class="total_stock"></span>件<br />
				可选择其它尺码继续录入</div>
			<div>
				&nbsp;
			</div>
			<input type="hidden" name="order_id" value="{{ d.order_id }}">
			<input type="hidden" name="url" value="{{ d.url }}">
			<input type="hidden" name="size_name" class="size_name_input" value="{{d.size_name }}" lay-reqText="尺码请选择">
			<input type="hidden" name="number" value="" lay-verify="required" lay-reqText="请扫描服装条码"  class="layui-input checkinNum">
			<div>&nbsp;</div>
		</div>
	</form>
</div>

<script type="text/html" title="操作按钮模板" id="buttonTpl22">
	{if $status ==2 }
	<a href="#" class="layui-btn layui-btn-normal layui-btn-sm tail-stock-outin" stocktype="not_defective" data-url="{:url('stockCheckIn')}?order_id={{d.order_id}}" data-id="{{d.order_id}}" data-ordernum="{{ d.client_ordernum}}" data-packagenum="{{ d.package_num}}" data-size="{{ d.size_name}}" data-diff="{{ d.tail_goods_dff}}" >库存录入</a>
	{/if}
</script>

<!--startprint-->
<div class="top_font_tail" >
	<span id="total_Num"></span>
	<span class="print_tuichu">
	<a href="#" class="layui-btn layui-btn-primary layui-btn-sm make-bill print" >打印</a>
	</span>
</div>
</div>
<table id="dataTable"></table>
<!--endprint-->

{include file="system@block/layui" /}

<script type="text/html" id="createTimeTpl">
	<div>{{layui.util.toDateString(d.create_time * 1000) }}</div>
</script>
<script type="text/html" id="updateTimeTpl">
	<div>{{layui.util.toDateString(d.update_time * 1000) }}</div>
</script>


<script type="text/html" id="idTpl">
	<input readonly="readonly" style="border: none;display: none" type="text" name="id" value="{{d.id}}">
</script>
<script type="text/html" id="over_status">
	<input readonly="readonly" style="border: none;display: none" type="text" name="id" value="{{d.id}}">
	{{# if(d.over_status==1){ }}
	<span style="color:#96d259">全部完成</span> <br>
	{{# }else if(d.over_status==2){  }}
	<span style="color:#96d259">无需处理</span> <br>
	{{# }else{ }}

	<span style="color:#96d259">已完成：{{d.tail_goods_dff}}件</span> <br>
	<span style="color:red">还差：{{d.diffNum}}件</span>

	{{# } }}
</script>
<script type="text/html" id="is_reason_content">
	<input readonly="readonly" style="border: none;display: none" type="text" name="id" value="{{d.id}}">
	{{# if(d.is_reason >0){ }}
		{{ d.reason_content}}
	{{# } }}
</script>

<script type="text/html" id="skuimgTpl">
	<span class="lay-pic-container" src="{{ d.ori_pic }}">
		<img src="{{ d.ori_pic }}" class="lay-pic">
	</span>
</script>

<script type="text/javascript">
	layui.use(['table', 'tool','layer','form','laytpl'], function() {
		var $ = layui.jquery;
		var table = layui.table;
		var layer = layui.layer;
		var form = layui.form;
		var laytpl=layui.laytpl;

		table.render({
			elem: '#dataTable'
			,url: "{:url('', ['action'=>'detailList','id_list'=>$id_list,'a'=>$a,'status'=>$status])}" //数据接口
//            ,page: true //开启分页
//            ,skin: 'row'
//            ,even: true
//            ,limit: 20
//            ,limits: [20,50,100,150,200]
			,text: {
				none : '暂无相关数据'
			}
			,toolbar: false
			,defaultToolbar: ['print']
			,cols: [[ //表头
				{type:'checkbox',field:'checkbox'}
				,{field: 'client_ordernum', title: '订单号',templet:'#OrdernumTpl',width:80}
				,{field: 'sku', title: 'sku',templet:'#SKUTpl',width:160}
				,{field: 'ori_pic', title: '图片',templet:skuimgTpl,width:80}
				,{field: 'size_name', title: '尺码',width:50}
				,{field: 'tail_goods_dff', title: '尾货件数',width:80}
				,{field: 'over_status', title: '总完成状态',templet:'#over_status',width:100}
				,{field: 'nick', title: '最后操作人',width:100}
				,{field: 'reason_content', title: '无需处理原因',templet:'#is_reason_content',width:100}
				,{field: 'available_count_total', title: '正品库存总数',width:100}
				,{field: 'factory_name', title: '工厂',width:100}
				,{field: 'create_time', title: '创建时间',templet: '#createTimeTpl', width:150}
				,{field: 'update_time', title: '操作日期',templet: '#updateTimeTpl', width:150}
				,{field: 'col3', title: '操作',templet: '#buttonTpl22', width:90}
			]]
			,done: function(res, curr, count){

				var a="{$a}";
				var status=res.status;
				var need_field=['checkbox','client_ordernum','sku','ori_pic','size_name','tail_goods_dff','over_status','nick','reason_content','factory_name','update_time'];
				$('table tr[data-index=0] td').each(function(i){
					if(need_field.indexOf($(this).attr('data-field'))==-1){
						$('td[data-field="'+$(this).attr('data-field')+'"]').remove();
						$('th[data-field="'+$(this).attr('data-field')+'"]').remove();
					}
				});

				$("#total_Num").html(res.total_count);

			}
		});
		window.status={$status};
		window.openPackageWindow = function(select) {
			if($(".layui-form-checked").size()<=0){
				layer.msg('请选择要操作的数据', {icon: 2,anim: 6});return;
			}
			var checkids='';
			var jsonlist='';
			var order_id_list='';
			var client_ordernum_list='';
			var that = $(document);
			var tableObj = that.attr('data-table') ? that.attr('data-table') : 'dataTable';
			var checkStatus = table.checkStatus(tableObj);
			for(var i=0;i<checkStatus.data.length;i++){
				      checkdata=checkStatus.data;
				    if(select==402){
						order_id_list += checkdata[i]['order_id']+",";
						client_ordernum_list += checkdata[i]['client_ordernum']+",";
						jsonlist += checkdata[i]['otherStockList_json'];
					}else{
						checkids+=checkdata[i]['client_ordernum']+'|'+checkdata[i]['size_name']+',';
					}
			}
			//调用库存
			if(select==402){
				openCallInventoryWindow(jsonlist,order_id_list,client_ordernum_list,window.status);
				return;
			}

			//预防重复提交
			var DISABLED='layui-btn-disabled';
			$(':button').addClass(DISABLED);
			$(':button').attr('disabled','disabled');
			setTimeout(function() {
				$(":button").removeClass(DISABLED);
				$(":button").removeAttr('disabled');
			}, 5000);//5秒后才能点击
			layer.confirm("确定要执行该操作吗？", {icon: 3,title:false, closeBtn:0, btn: ['确定','取消']}
					, function(){
						$.post("{:url('index')}", {action:'detail_out',ids_str:checkids,status:{$status}}, function (res) {
							if (res.code == 1) {
								layer.msg(res.msg, {time: 1000, icon: 1}, function () {
									//statCli(1);
									location.reload();
									//reloadTable();
								});
							} else {
								layer.msg(res.msg, {time: 1800, icon: 2});
								//移除按钮状态
								$(':button').removeClass(DISABLED);
								$(':button').removeAttr('disabled');
							}
						}, 'json');
					}, function(){
						layer.closeAll();
					});
		}

		<!--调用库存 start-->
		//调用库存
		var sku_stock='';
		window.openCallInventoryWindow = function(dress_line_code_list='',order_id_list='',client_ordernum_list='',status=0) {
			sku_stock=dress_line_code_list;
			console.log(sku_stock);
			var d = [];
			d['url'] = "{:url('stockCheckOut')}?order_id="+order_id_list;
			d['order_id'] = order_id_list;
			d['client_ordernum'] = client_ordernum_list;
			d['sku_stock'] = dress_line_code_list;
			$(".size_name_span").html("__");
			$(".size_name_input").val('');
			$(".scan_code").show();
			$(".checkin_ret").hide();
			$(".out_code_input").focus();
			var content = laytpl($('#StockCheckOut').html()).render(d);
			layerStockOut = layer.open({
				type: 1
				,area: ['660px','320px']
				,offset: '100px'
				//,shade:[0.8, '#393D49']
				,anim: 5
				,skin:'layui-layer-molv'
				,title:'库存调用-你选择占用库存的订单号：'+client_ordernum_list
				,content: content
				,success:function(layerdom,index){
					$(".out_code_input").eq(1).focus();
				}
			});
		};

		$(document).on('input propertychange',".out_code_input", function() {
			var dress_line_code=$(this).val();
			if(dress_line_code==''){
				return;
			}
			var code_str=',';
			console.log(sku_stock);
			code_str=sku_stock;
			if(dress_line_code.length==17){
				dress_line_code=dress_line_code+"\n";
			}
			var codeNumbers=dress_line_code.split("\n");
			var last_input=codeNumbers[codeNumbers.length-1];
			var r, re;
			var re = eval('/'+last_input+'/ig');
			r = dress_line_code.match(re);   //匹配字符
			$(".scan_code_ret").html('');

			for(var i=0;i<codeNumbers.length;i++){
				if(code_str.indexOf(codeNumbers[i])!=-1){
				}else{
					$(".scan_code_ret").eq(1).html("未找到"+codeNumbers[i]+"的库存信息或该条码不属于当前sku");
				}
			}
			if(codeNumbers[codeNumbers.length-1].length>=17){
				//$(".code_input").eq(1).val(dress_line_code+'\n');
			}
			$(".outcheckinNum").val(codeNumbers.length);
			$(".checkInNumSpan").html(codeNumbers.length);
		});

		form.on('submit(stock-out-out)', function (data) {
			var url = data.field.url;
			$.ajax({
				type: "POST",
				url: url,
				data: data.field,
				dataType:"json",
				success: function(res){
					if (res.code == 1) {
						$('#stockOutInTpl form')[0].reset();
						$(".total_stock").html(res.data.available_count);
						$(".scan_code").hide();
						$(".checkin_ret").show();
						$(".act_ret_str").html(res.data.act_ret_str);
						layer.msg(res.msg, {icon: 1,end:function(){
								location.reload();
							}});
					} else {
						layer.msg(res.msg, {icon: 2,anim: 6});
					}
				}
			});
			return false;
		});
		<!--调用库存 end-->

		//库存录入 start
		var layerStockOutIn = null;
		$(document).on('click','.tail-stock-outin',function(){
			var orderId = $(this).attr('data-id'),title=$(this).text(),stocktype=$(this).attr("stocktype");
			var orderNum=$(this).attr('data-ordernum');
			var url = $(this).attr('data-url');
			var json = $(this).attr('data-json');
			var packageNum=$(this).attr('data-packagenum');
			var size_name=$(this).attr('data-size');
			var tail_goods_dff=$(this).attr('data-diff');
			var d = [];

			d['sku_stock']=json;
			d['url'] = url;
			d['order_id'] = orderId;
			d['stocktype'] = stocktype;
			d['client_ordernum'] = orderNum;
			d['package_num'] = packageNum;
			d['size_name'] = size_name;
			d['tail_goods_dff'] = tail_goods_dff;


			var content = laytpl($('#StockCheckIn').html()).render(d);
			layerStockOutIn = layer.open({
				type: 1
				,area: ['650px','350px']
				,offset: '100px'
				,shade:[0.3, '#393D49']
				,anim: 5
				,shadeClose:true
				,skin:'layui-layer-molv'
				,title:title+'-当前入库的订单号：'+orderNum
				,content: content
			});
		});
		form.on('submit(stock-out-in)', function (data) {
			var url = data.field.url;
			$.ajax({
				type: "POST",
				url: url,
				data: data.field,
				dataType:"json",
				success: function(res){
					if (res.code == 1) {
						$('#StockCheckIn form')[0].reset();
						//layer.close(layerStockOutIn);
						$(".total_stock").html(res.data.available_count);
						$(".checkInNumSpan").html(res.data.checkin_count);
						$(".size_name_span").html(res.data.size_name);
						$(".scan_code").hide();
						$(".checkin_ret").show();
						$(".checkinNum").eq(0).val('');
						$(".checkinNum").eq(1).val('');
						layer.msg(res.msg, {time: 2000, icon: 1}, function () {
							location.reload();
						});
					} else {
						layer.msg(res.msg, {icon: 2,anim: 6});
					}
				}
			});

			return false;
		});
		$(document).on('click','.show_code_input',function(){
			$(".size_name_span").html($(this).attr('size_name'));
			$(".size_name_input").val($(this).attr('size_name'));
			$(".checkInNumSpan").html(0);
			$(".scan_code").show();
			$(".checkin_ret").hide();
			$(".code_input").eq(1).val('');
			$(".code_input").eq(1).focus();
		});
		$(document).on('input propertychange',".code_input", function() {
			var dress_line_code=$(this).val();
			if(dress_line_code==''){
				return;
			}
			var codes=dress_line_code.replace(/\n/g,"");
			var input_count=0;
			codes=codes.replace(/\r/g,"");
			var codeNumbers=codes.split(";");
			if(codeNumbers[codeNumbers.length-1].length>=17){
				$(".code_input").eq(1).val(codes+';');
				input_count=1;
			}
			$(".checkinNum").val(codeNumbers.length-1+input_count);
			$(".checkInNumSpan").html(codeNumbers.length-1+input_count);

		});
		<!--库存录入 end-->

		// 刷新当前页
		window.reloadTable = function () {

			var that = $("#hisi-table-search"),
					arr = that.serializeArray(),
					where = new Array(),
					dataTable = that.attr('data-table') ? that.attr('data-table') : 'dataTable',

					currPage = $(".layui-laypage-em").next().html(),
					options = new Function('return '+ that.attr('hisi-data'))() || {page: {curr:currPage}};
			for(var i in arr) {
				where[arr[i].name] = arr[i].value;
			}
			options.url = that.attr('action');
			options.where = where;

			opTable.reload(options);
			return false;
		}

		// 打印
		layui.$('.print').on('click', function () {
			Print()
		});
		function  Print(){

			$("title").text('');
			$("div").css({"overflow":"hidden"});
			$(".layui-table-col-special").remove();
			$(".laytable-cell-checkbox").remove();
			$(".laytable-cell-1-0-9").remove();
			$(".print_tuichu").remove();

			bdhtml = window.document.body.innerHTML;
			sprnstr = "<!--startprint-->";  //开始打印标识字符串有17个字符
			eprnstr = "<!--endprint-->";    //结束打印标识字符串
			prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);  //从开始打印标识之后的内容
			prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));  //截取开始标识和结束标识之间的内容
			window.document.body.innerHTML = prnhtml;  //把需要打印的指定内容赋给body.innerHTML
			window.print();  //调用浏览器的打印功能打印指定区域
			location.reload();  //重新给页面内容赋值；
		}

	});
</script>